package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.*;
import com.baizhi.cmfz.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;
    @Autowired
    private AdminDao adminDao;
    @Autowired
    private AdminRoleDao adminRoleDao;
    @Autowired
    private RoleResourceDao roleResourceDao;
    @Autowired
    private ResourceDao resourceDao;


    //获取用户的角色信息
    @Override
    public Set<String> getAllRolesByUsername(String username) {
        int adminId = adminDao.getAdminIdByUsername(username);
        int roleId = adminRoleDao.getRolrIdByAdminId(adminId);
        Set<String> roleNames = roleDao.getRoleNameByRoleId(roleId);

        return roleNames;
    }
    // 获取用户的权限信息
    public Set<String> getAllResourcesByUsername(String username){
        int adminId = adminDao.getAdminIdByUsername(username);
        int rolrId = adminRoleDao.getRolrIdByAdminId(adminId);
        List<Integer> resourceIds = roleResourceDao.getResourceIdByRoleId(rolrId);

        Set<String> resourceNames = resourceDao.getResourceNameByResourceId(resourceIds);
        return resourceNames;
    }
}
